module.exports = class extends think.Model {
  queryAll(field = '*') {
    return this.where({
      status: 1 // 上线
    }).field(field).select();
  }
  queryFee(categoryId) {
    return this.where({
      id: categoryId
    }).getField('fee', true);
  }
  create({
    title,
    cover
  }) {
    return this.add({
      title,
      cover,
      create_time: think.datetime()
    });
  }
  updateById(id, {title, cover}) {
    return this.where({
      id
    }).update({
      title,
      cover,
      modify_time: think.datetime()
    });
  }
  _updateStatus(id, status) {
    return this.where({id}).update({
      status,
      modify_time: think.datetime()
    });
  }
  // 上线
  setOnline(id) {
    return this._updateStatus(id, 1);
  }
  // 下线
  setOffline(id) {
    return this._updateStatus(id, 0);
  }
};
